// Header File
// Created 11/19/2007; 6:37:58 PM

#ifndef __TERRAIN_H__
#define __TERRAIN_H__

#include "Globals.h"	

//defines the map indices
#define WATER     0
#define DESERT    1
#define GRASSLAND 2
#define PLAINS    3
#define TUNDRA    4
#define FOREST    5
#define HILLS     6
#define PEAKS     7		

//Terrain Structure
typedef struct
{
	// Stats
	char name[10];
	char movecost;
	char defense, food, shields, trade;
	
	// Irrigation
  bool irrigate;
  char iBonus, iTurns, iAI;
  
  // Mining
  bool mine;
  char mBonus, mTurns, mAI;
} Terrain;

// Array for the terrain stats
Terrain terrain[8];

//TBonus Structure
typedef struct
{
	// Stats
	char name[13];
	char movecost;
	char defense, food, shields, trade;
	char terrain;
} TBonus;

// Array for the terrain stats
TBonus tBonus[21];

#ifndef INSTALL

// Index Array
char tIndex[8][2] = {{0,1},{2,1},{4,2},{7,3},{11,0},{12,3},{16,1},{18,1}};

// Creates the sprites for the cities
unsigned short int citypic[9] =  {0x0000,0x0000,0x4900,0x7F00,0x7F00,0x7F00,0x7F00,0x7F00,0x7F00};

// Creates the sprite for a full square
//unsigned short int black[9] =  {0xFFC0,0xFFC0,0xFFC0,0xFFC0,0xFFC0,0xFFC0,0xFFC0,0xFFC0,0xFFC0};
//unsigned short int black[9] =  {0xAA80,0x5540,0xAA80,0x5540,0xAA80,0x5540,0xAA80,0x5540,0xAA80};
unsigned short int black[9] =  {0x5540,0xAA80,0x5540,0xAA80,0x5540,0xAA80,0x5540,0xAA80,0x5540};

// Creates the sprite for the cursor
unsigned short int cursorpic[11] = {0xAAA0,0x0000,0x8020,0x0000,0x8020,0x0000,0x8020,0x0000,0x8020,0x0000,0xAAA0};

// Creates array for names of the types of terrain improvements
char improv_name[4][11] = {"Road", "Irrigation", "Mine", "Railroad"};

// Array for names of resource emphasis
char resource_emph_name[4][10] = {"Balanced", "Food", "Shields", "Trade"};


////////////////////////////
// Terrain Methods /////////
////////////////////////////
void ImproveCityTerrain(char civ, char city);

void BuildRoad(int x, int y);
void BuildIrrigation(int x, int y);
void BuildMine(int x, int y);
void BuildRailroad(int x, int y);

bool HasRoad(int x, int y);
bool HasIrrigation(int x, int y);
bool HasMine(int x, int y);
bool HasRailroad(int x, int y);


////////////////////////////
// Drawing Macros //////////
////////////////////////////

#define ClrCursorMenu() Clr(112, 6, 158, 27);
#define ClrSide() Clr(111, 30, 160, 99);
#define ClrSide2(X) Clr(111, X, 160, 99);
#define DrawMapSquare(X, Y) Sprite16(10*(X - 5*game.qX -1)+1, 10*(Y - 3*game.qY -1)+30, SPRITE_HEIGHT, &game.backpic[(Worldmap(3*qY+Y-1,5*qX+X-1)-1)*SPRITE_HEIGHT], LCD_MEM, SPRT_OR);
#define DrawCity2() Sprite16(111, 26, SPRITE_HEIGHT, citypic, LCD_MEM, SPRT_OR);

#else

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CreateT ////////////////////////////////////////////////////////////////////////////////////////////////////////
// sets all the values in the array for one different type of terrain /////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CreateT(char i, char *name, char movecost, char defense, char food, char shields, char trade,
									 	 bool irrigate, char iBonus, char iTurns, char iAI,
									 	 bool mine, char mBonus, char mTurns, char mAI)
{
	strcpy(terrain[i].name, name);
	terrain[i].movecost = movecost;
	terrain[i].defense = defense;
	terrain[i].food = food;
	terrain[i].shields = shields;
	terrain[i].trade = trade;
	terrain[i].irrigate = irrigate;
  terrain[i].iBonus = iBonus;
  terrain[i].iTurns = iTurns;
  terrain[i].iAI = iAI;
  terrain[i].mine = mine;
  terrain[i].mBonus = mBonus;
  terrain[i].mTurns = mTurns;
  terrain[i].mAI = mAI;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CreateTerrain //////////////////////////////////////////////////////////////////////////////////////////////////
// sets all the values in the array for the different types of terrain ////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CreateTerrain()
{
	//                  							M  D  F  S  T  I  B  T  A  M  B  T  A
	CreateT(WATER, 			"Sea",				1, 2, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0);
	CreateT(DESERT, 		"Desert",			1, 2, 0, 1, 0, 1, 1, 5, 6, 1, 1, 5, 5);
  CreateT(GRASSLAND, 	"Grassland",	1, 2, 2, 1, 0, 1, 1, 5, 4, 0, 0, 0, 0);
  CreateT(PLAINS,		  "Plains",			1, 2, 1, 1, 0, 1, 1, 5, 3, 0, 0, 0, 0);
  CreateT(TUNDRA,	 		"Tundra", 		1, 2, 1, 0, 0, 1, 1,10, 2, 0, 0, 0, 0);
  CreateT(FOREST, 		"Forest",			2, 3, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  CreateT(HILLS, 			"Hills",			2, 4, 1, 0, 0, 1, 1,10, 3, 1, 3,10, 5);
  CreateT(PEAKS, 			"Peaks",			3, 6, 0, 1, 0, 0, 0, 0, 0, 1, 1,10, 7);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CreateT ////////////////////////////////////////////////////////////////////////////////////////////////////////
// sets all the values in the array for one different type of terrain /////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CreateTB(char i, char *name, char movecost, char defense, char food, char shields, char trade, char terrain)
{
	strcpy(tBonus[i].name, name);
	tBonus[i].movecost = movecost;
	tBonus[i].defense = defense;
	tBonus[i].food = food;
	tBonus[i].shields = shields;
	tBonus[i].trade = trade;
	tBonus[i].terrain = terrain;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CreateTerrain //////////////////////////////////////////////////////////////////////////////////////////////////
// sets all the values in the array for the different types of bonus terrain //////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CreateTBonus()
{
	//           N              M D F S T  T
	CreateTB(0,  "Fish", 				1,2,3,0,2, WATER);
	CreateTB(1,  "Whales", 			1,2,2,2,3, WATER);
	CreateTB(2,  "Oasis", 			1,2,3,1,0, DESERT);
	CreateTB(3,  "Desert Oil",  1,2,0,4,0, DESERT);
	CreateTB(4,  "Game", 				1,2,3,1,0, GRASSLAND);
	CreateTB(5,  "Wine", 				2,4,1,0,4, GRASSLAND);
	CreateTB(6,  "Fruit", 			2,3,4,0,1, GRASSLAND);
	CreateTB(7,  "Buffalo", 		1,2,1,3,0, PLAINS);
	CreateTB(8,  "Ivory", 			2,2,1,1,4, PLAINS);
	CreateTB(9,  "Wheat",				1,2,3,1,0, PLAINS);
	CreateTB(10, "Silk", 				2,3,1,2,3, PLAINS);
	CreateTB(11, "Glacier Oil", 2,2,0,4,0, TUNDRA);
	CreateTB(12, "Pheasant", 		2,3,3,2,0, FOREST);
	CreateTB(13, "Peat", 				2,3,1,4,0, FOREST);
	CreateTB(14, "Furs", 				1,2,2,0,3, FOREST);
	CreateTB(15, "Spice", 			2,3,3,0,4, FOREST);
	CreateTB(16, "Coal", 				2,4,1,2,0, HILLS);
	CreateTB(17, "Iron", 				3,6,0,4,0, HILLS);
	CreateTB(18, "Gold", 				3,6,0,1,6, PEAKS);
	CreateTB(19, "Gems", 				2,3,1,0,4, PEAKS);
}

#endif // !INSTALL

#endif
